package com.lottery.im.module.result.adapter.result.item;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lottery.im.R;
import java.util.List;

public class HorizontalPk30Adapter extends BaseAdapter {

  private List<String> mDataList;
  private Context mContext;

  public HorizontalPk30Adapter(Context context, List<String> list) {
    mDataList = list;
    mContext = context;
  }

  @Override public int getCount() {
    return mDataList.size();
  }

  @Override public Object getItem(int position) {
    if (position >= mDataList.size() || position < 0) return null;
    return mDataList.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(final int position, View v, ViewGroup parent) {
    final ViewHolder holder;
    if (v == null) {
      v = LayoutInflater.from(mContext).inflate(R.layout.item_horizontal_pk30_list, parent, false);
      holder = new ViewHolder();
      holder.num = v.findViewById(R.id.tv_num);
      v.setTag(holder);
    } else {
      holder = (ViewHolder) v.getTag();
    }
    holder.num.setText(mDataList.get(position));
    holder.num.setBackgroundResource(getResourceId("pk_ball_" + mDataList.get(position)));
    return v;
  }

  class ViewHolder {
    protected TextView num;
  }

  //根据图片名称取得对应图片
  public int getResourceId(String name) {
    int resId = mContext.getResources().getIdentifier(name, "drawable", mContext.getPackageName());
    //解析资源文件夹下，id为resId的图片
    return resId;
  }
}